package level.editor.view.frame;

import java.awt.Point;

import javax.swing.Icon;
import javax.swing.JInternalFrame;

import level.editor.view.group.Group;
import level.editor.view.group.Item;

public class InternalFrame extends JInternalFrame
{
	public static final Integer Z_ORDER = 0;

	public InternalFrame(String name, Icon icon)
	{
		super(name, true, true, true, true);
		setFrameIcon(icon);
		init();
	}

	public String getTitle()
	{
		return getContentPane().getName(); // Does not update automatically
	}

//	public Icon getFrameIcon()
//	{
//		if (getContentPane() instanceof Group)
//		{
//			return ((Group) getContentPane()).getIcon();
//		}
//		else
//			return null;
//	}

	public void addItem(Item item)
	{
		Group group = (Group) getContentPane();
		group.add(item);
		setMinimumSize(group.getMinimumSize());
		setSize((int) (getSize().getWidth() > getMinimumSize().getWidth() ? getSize()
				.getWidth() : getMinimumSize().getWidth()), (int) (getSize()
				.getHeight() > getMinimumSize().getHeight() ? getSize()
				.getHeight() : getMinimumSize().getHeight()));
	}

	public Group getGroup()
	{
		return (Group) getContentPane();
	}

	public void setOrigin(Point origin)
	{
		this.origin = origin;
	}

	public Point getOrigin()
	{
		return origin;
	}

	private void init()
	{
		Group group = new Group();
		setBounds(10, 10, 300, 300);
		setContentPane(group);
		setVisible(true);
	}

	protected Point origin;
}
